package com.jxd.ordering.util;

import com.jxd.ordering.controller.PermissionController;
import com.jxd.ordering.exception.serviceexception.PermissionNotAllowedException;

/**
 * @ClassName PermissionUtil
 * @Description TODO
 * @Author Ankailong
 * @Date 2022/9/29
 * @Version 1.0
 * 权限控制
 */
public class PermissionUtil {
    /**
     * 权限控制
     * @param permission 用户权限等级
     * @param level 接口权限等级
     * @throws PermissionNotAllowedException 抛出用户无权访问异常
     */
    public static void PermissionControl(Object permission, int level) throws PermissionNotAllowedException {
        try {
            if (Integer.parseInt(permission.toString()) < level) {
                throw new PermissionNotAllowedException();
            }
        } catch (Exception e) {
            throw new PermissionNotAllowedException();
        }
    }
}
